package com.itany.task.task.thread;

import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.stereotype.Component;

@Component
@EnableAsync//开启异步任务
public class TestTread {

    @Async("myExecutor")
    public void a(){
        for (int i = 0; i < 10; i++) {

            try {
                Thread.sleep(1);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }

            System.out.println("TestTread.a() "+Thread.currentThread().getName());
        }
    }

    @Async("myExecutor")
    public void b(){
        for (int i = 0; i < 10; i++) {

            try {
                Thread.sleep(1);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }

            System.out.println("TestTread.b() "+Thread.currentThread().getName());
        }
    }

}
